package com.example.jiaju.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.jiaju.R;
import com.example.jiaju.databinding.DecorationItemBinding;
import com.example.jiaju.entity.DecAndWork;
import com.example.jiaju.entity.Decoration;

import java.util.Arrays;
import java.util.List;

public class DecorateAdapter extends RecyclerView.Adapter<DecorateAdapter.MyViewHolder>{

    public List<DecAndWork.PageDTO> list;
    private Context context;

    public DecorateAdapter(List<DecAndWork.PageDTO> list,Context context) {
        this.list = list;
        this.context=context;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        DecorationItemBinding binding=
                DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),
                        R.layout.decoration_item,parent,false);
//        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.decoration_item,parent,false);
        MyViewHolder myViewHolder=new MyViewHolder(binding.getRoot());
        myViewHolder.binding=binding;
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {

        //有作品才加在到页面
        if(list.get(position).works.size()!=0){
            holder.binding.setItem(list.get(position));
            String string[]=list.get(position).works.get(0).workPic.split(",");
            holder.binding.setImg1(string[0]);
            holder.binding.setImg2(string[1]);
        }else{

        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder{
        DecorationItemBinding binding;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
}
